﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Microsoft.Office.Interop.Excel;

namespace GailsMacro
{
    static class ExcelProcessing
    {

        public static void CreateSpreadsheet()
        {
            try
            {
                // Instantiate excel application
                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                //xlApp.Visible = true;

                // Instantiate workbook
                Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

                // Instantiate worksheet
                Worksheet ws = (Worksheet)wb.Worksheets[1];

                // Copy clipboard to excel
                ws.Paste();

                // Bold top row
                ws.Rows[1].Font.Bold = true;

                // Autofit all cell width
                ws.Columns.AutoFit();

                // Select All data from worksheet and put into clipboard
                Microsoft.Office.Interop.Excel.Range last = ws.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
                Microsoft.Office.Interop.Excel.Range range = ws.get_Range("A1", last);
                range.Copy();

                // Close workbook and quit excel application
                wb.Close(0);
                xlApp.Quit();

            }
            catch (Exception)
            {
                throw new Exception("This macro sucks....");
            }

        }

    }
}
